<template>
  <div>
    <el-dialog v-model="state.showDialog" destroy-on-close :title="title" draggable :close-on-click-modal="false"
      :close-on-press-escape="false" width="260px">
      <el-form ref="formRef" :model="form">
        <el-row>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
            <el-form-item label="次数" prop="writeCount"
              :rules="[{ required: false, message: '请输入次数', trigger: ['blur', 'change'] }]">
              <el-input-number v-model="form.writeCount" />
            </el-form-item>
          </el-col>
        </el-row>
        <row>
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
            <el-form-item label="参数" prop="dataSize"
              :rules="[{ required: false, message: '请写入任意标准类型值', trigger: ['blur', 'change'] }]">
              <el-input min="0" v-model="form.writeValue" placeholder="请输入任意标准类型值" autocomplete="off" clearable />
            </el-form-item>
          </el-col>
        </row>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="onCancel" size="default">取 消</el-button>
          <el-button type="primary" @click="onSure" size="default" :loading="state.sureLoading">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script setup lang="ts" name="industry/station-block-write/form">
import { reactive, toRefs, ref } from 'vue'
import { BlockOffsetInsertValueInput } from '/@/api/industry/data-contracts'
import { BlockOffsetApi } from '/@/api/industry/BlockOffset'
const state = reactive({
  showDialog: false,
  sureLoading: false,
  form: {} as BlockOffsetInsertValueInput,
})
const { form } = toRefs(state)
const formRef = ref()
defineProps({
  title: {
    type: String,
    default: '',
  },
})

const open = (row: any) => {
  state.form = { blockOffsetId: row.blockOffsetId } as BlockOffsetInsertValueInput
  state.showDialog = true
}

// 确定
const onSure = () => {
  formRef.value.validate(async (valid: boolean) => {
    if (!valid) return
    state.sureLoading = true
    const res = await new BlockOffsetApi().insertOffsetValue(state.form, { showSuccessMessage: true }).catch(() => {
      state.sureLoading = false
    })
    state.sureLoading = false
    if (res?.success) {

      state.showDialog = false
    }
  })
}


// 取消
const onCancel = () => {
  state.showDialog = false
}
defineExpose({
  open,
})
</script>